package com.digitalchina.lxnsy.activity.old;

import android.os.Handler;
import android.os.Message;
import android.widget.Button;
import android.widget.EditText;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.api.BusinessTraining;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.constant.Constant;
import com.digitalchina.lxnsy.constant.MSG;
import com.digitalchina.lxnsy.toolkit.RegexpUtil;
import com.digitalchina.lxnsy.toolkit.StringUtil;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.activity
 * 创建人：郑皓
 * 创建时间：2017/2/28 16:24
 * 修改备注：
 * ================================================
 */
public class SignInInfoActivity extends BaseActivity {

    @Bind(R.id.sign_in_info_tv_name)
    EditText signInInfoTvName;
    @Bind(R.id.sign_in_info_tv_phone)
    EditText signInInfoTvPhone;
    @Bind(R.id.sign_in_info_btn_submit)
    Button signInInfoBtnSubmit;

    private String trainingCode;

    @Override
    public void setLayout() {
        setContentLayout(R.layout.activity_sign_in_info);
        setTitle("签到信息");
    }

    @Override
    public void initMember() {
        if (getIntent().hasExtra("trainingCode")) {
            trainingCode = (String) getIntent().getSerializableExtra("trainingCode");
        }
    }

    @Override
    public void addListener() {

    }

    @Override
    public void setHandler() {
        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                switch (msg.what) {
                    case MSG.MSG_TRAINING_SIGN_SUCCESS:
                        showToast("签到成功");
                        setResult(RESULT_OK);
                        finish();
                        break;
                    case MSG.MSG_TRAINING_SIGN_FIELD:
                        showToast(msg.obj.toString());
                        break;
                }
            }
        };
    }

    @Override
    public void callBack(Object object) {

    }

    @Override
    public void rightOnClick() {

    }

    @OnClick(R.id.sign_in_info_btn_submit)
    public void onClick() {

        String name = StringUtil.getEditText(signInInfoTvName);
        String phone = StringUtil.getEditText(signInInfoTvPhone);

        if (StringUtil.isStrEmpty(name)) {
            showToast("请填写签到用户");
            return;
        }
        if (StringUtil.isStrEmpty(phone)) {
            showToast("请填写签到用户手机号");
            return;
        }
        if (!RegexpUtil.isRegexpValidate(phone, Constant.REGEX_MOBILE_SIMPLE)) {
            showToast("请填写合法的手机号码");
            return;
        }

        BusinessTraining.signForApp(this, name, phone, trainingCode, mHandler);
    }
}
